<?php
namespace app\api\validate;

class IDCollection extends BaseValidate{
    protected $rule = [
        'ids' => 'require|checkIDs'
    ];

    protected $message = [
        'ids.require' => 'ids为必填项',
        'ids.checkIDs' => 'ids参数必须为以逗号分隔的多个正整数'
    ];

    //自定义验证规则
    protected function checkIDs($value, $rule='', $data='', $field=''){
        $values = explode(',', $value);
        if(empty($values)){
            return false;
        };
        foreach($values as $id){
            if(!$this->isPositiveInterger($id)){
                return false;
            }
        };
        return true;
    }
}

?>